;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname issues) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Issue 1 ;; Data Definitions that do not capture mutual recursion ;; ;; StringSection ;; ;; A StringSection is one of the following ;; -- (cons String empty) ;; a list whose first element is a string and other element is empty ;; -- (cons string StringSection) ;; represents a list whose first is a string and the other element is a ;; stringsection ;; TEMPLATE: ;; string-section-fn : Section -> ?? ;; (define (string-section-fn ssec) ;; (cond ;; [(empty? (rest ssec) (... (first ssec))] ;; [else (... (first ssec) ;; (string-section-fn (rest ssec)))])) ;; ;; NestedRep ;; ;; A NestedRep (NR) is one of ;; -- empty ; empty ;; -- (cons StringSection NestedRep) ; (cons Section NR) represents a list ;; whose first element is Sexp and whose ;; other elements are represented ;; by ListOfSexp. ;; ;; TEMPLATE: ;; nested-rep-fn : NestedRep -> ?? ;; (define (nested-rep-fn nr) ;; (cond ;; [(empty? nr) (string-section-fn (first nr))] ;; [else (... (section-fn (first nr)) ;; (nested-rep-fn (rest nr)))])) ;; SHOULD HAVE BEEN SOMETHING LIKE ;; A Section is a (list SectionNumber ListOfSections) ;; A ListOfSections is one of ;; empty ;; (cons Section ListOfSections) ;; An Outline is a ListOfSections ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Issue 2 ;; Idiosyncratic way of defining lists ;; ;; A FlatRep (FR) is one of ;; -- empty ;; Interpretation: The FlatRep is an empty list ;; -- (cons FlatRepSection empty) ;; Interpretation: A list where the first element is a FlatRepSection ;; and the other element is empty. ;; -- (cons FlatRepSection FlatRep) ;; Interpretation: Represents a list whose first element is ;; FlatRepSection and whose other elements are represented by FlatRep. ;; TEMPLATE: ;; flat-rep-fn : FlatRep -> ?? ;; (define (flat-rep-fn fr) ;; (cond ;; [(empty? fr) empty] ;; [(empty? (rest fr)) (frsection-fn (first nr)] ;; [else (... (frsection-fn (first fr)) ;; (flat-rep-fn (rest fr)))])) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Issue 3 ;; Invariants that don't really capture anything ;; ;; nested-to-flat : NestedRep -> FlatRep ;; GIVEN: a nested representation of a list ;; RETURNS: the flat representation of the given list ;; EXAMPLES: (nested-to-flat outline-list) -> flat-list ;; STRATEGY: Function Composition (define (nested-to-flat nr) (nested-to-flat-from nr LONI)) ;; TESTS: (begin-for-test (check-equal? (nested-to-flat outline-list) flat-list) (check-equal? (nested-to-flat empty-list) empty)) ;; nested-to-flat-from : NestedRep LONI -> FlatRep ;; (ORIGINAL:) ;; GIVEN: a nested representation of a list and a list of non neg integers ;; WHERE: LONI is used to convert the first string of nested representation ;; to flat representation ;; RETURNS: the flat representation of the given nestedrep with the help of the ;; list of non-neg integers ;; EXAMPLES: (nested-to-flat-from outline-list LONI) -> flat-list ;; STRATEGY: Structural Decomposition on nr : NestedRep ;; (BETTER:) ;; GIVEN: a nested representation of a section of some outline and a ;; list of non neg integers. ;; WHERE: LONI represents the section number of this section in the ;; larger outline. ;; RETURNS: the flat representation of the given section of the outline. ;; EXAMPLES: (nested-to-flat-from outline-list LONI) -> flat-list ;; STRATEGY: Structural Decomposition on nr : NestedRep ;; (OR EVEN BETTER:) ;; GIVEN: a nested representation of a section of some outline and the ;; section number of that section. ;; RETURNS: the flat representation of the given section of the outline. ;; EXAMPLES: (nested-to-flat-from outline-list LONI) -> flat-list ;; STRATEGY: Structural Decomposition on nr : NestedRep ;; (OR MAYBE HE MEANT:...) ;; GIVEN: A nested representation of some list of sections at the same ;; level in an outline, and the section number of the first one. ;; RETURNS: the flat representation of the given list of sections. ;; BUT WAIT! If the list of sections is empty, what do you mean by ;; "the section number of the first one."? Houston, we have a problem. (define (nested-to-flat-from nr LONI) (cond [(empty? nr) empty] [(empty? (rest nr)) (string-to-flat (first nr) LONI)] [else (append (string-to-flat (first nr) LONI) (nested-to-flat-from (rest nr)(update-loni LONI)))])) ;; next-loni : LONI -> LONI ;; GIVEN: a section number ;; RETURNS: the next section number at the same level ;; EXAMPLES: (update-loni LONI)->(1) ;; STRATEGY: Structural Decomposition on LONI : ListOfNonNegInt (define (update-loni LONI) (cond [(empty? (rest LONI)) (cons (+ 1 (first LONI))(rest LONI))] [else (cons (+ 1 (first LONI))(rest LONI))])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Issue 4 ;; No documentation on whether the ListOfNonNegInts in the FlatRep can ;; be any ListOfNonNegInts ;; ;; NonNegIntegerSection ;; ;; A NonNegIntegerSection (NIS) is one of the following ;; -- (cons NonNegInteger empty) ;; First element represent positive integer and other is empty ;; -- (cons NonNegInteger NonNegIntegerSection) ;; First element represent positive integer and other is NonNegIntegerSection ;; TEMPLATE: ;; nisection-fn : NonNegIntegerSection -> ?? ;; (define (nisection-fn nisec) ;; (cond ;; [(empty? (rest sec) (... (first nisec))] ;; [else (... (first nisec) ;; (nisection-fn (rest sec)))])) ;; FlatRepSection ;; ;; A FlatRepSection (FRS) is one of the following ;; -- (cons NonNegIntegerSection String) ;; First part of the element is NonNegIntegerSection and other is string ;; TEMPLATE: ;; frsection-fn : Section -> ?? ;; (define (frsection-fn frsec) ;; (... (nisection-fn (first frsec)) ;; (second frsec))) ;; FlatRep ;; ;; A FlatRep (FR) is one of ;; -- (cons FlatRepSection empty) ; (cons FlatRepSection empty) first ;; element is Sexp and other is empty ;; -- (cons FlatRepSection FlatRep) ; (cons FlatRepSection FR) represents a ;; list whose first element is Sexp and ;; whose other elements are represented ;; by ListOfSexp. ;; ;; TEMPLATE: ;; flat-rep-fn : FlatRep -> ?? ;; (define (flat-rep-fn fr) ;; (cond ;; [(empty? (rest fr)) (frsection-fn (first nr)] ;; [else (... (frsection-fn (first fr)) ;; (flat-rep-fn (rest fr)))])) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;